package com.atguigu;

import com.atguigu.domain.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * Application
 *
 * @Author: 马伟奇
 * @CreateTime: 2021-02-23
 * @Description:
 * @SpringBootApplication:表示当前类跟springboot框架进行关联
 *
 * @ComponentScan:组件扫描,是以为起点进行扫描
<context:component-scan base-package="com.atguigu"></context:component-scan>
 @Configuration:配置类
 spring.xml
 <bean id="对象名字" class="全路径名字"></bean>

 @SpringBootConfiguration:相当于一个配置类,相当于springl.xml

 @EnableAutoConfiguration:表示开启自动配置
 */
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        // 启动springboot
        // 第一个参数：表示当前类的字节码
        ApplicationContext context = SpringApplication.run(Application.class, args);
        // 获取spring容器管理的对象 spring.xml
        // <bean id="application" class="com.atguigu.Application">
//        for (String name : context.getBeanDefinitionNames()) {
//            System.out.println(name);
//        }
        User user = (User) context.getBean("user");
        System.out.println(user);
    }

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}